<?php

class LoanProducts extends HTech_Db_Table
{
    protected $_name    = 'view_loan_products';
    protected $_primary = 'LoanProductId';  
    
    protected function _setGridMetadata()
    {
        $this->_gridMetadata['title'] = $this->translate("Loan products");
        $this->_gridMetadata['onClick'] = 'loan.loan-product.add';
        $this->_gridMetadata['headers'] = array
            (
                array('LoanProductId',        30, $this->translate("Id"),               'Number'),
                array('Name',                250, $this->translate("Name"),             'String'),
                array('InterestCalculation', 100, $this->translate("Interest calc."),   'String'),
                array('Installments',        100, $this->translate("Installments"),     'Number'),
                array('PaymentFrequency',     80, $this->translate("Pmt freq."),        'String'),
                array('AnnualPercentageRate', 70, $this->translate("APR"),              'Number',   'Standard'),
                array('LoanInsurancePct',    100, $this->translate("Loan insurance"),   'Number',   'Standard'),
                array('HealthInsurancePct',  100, $this->translate("Health insurance"), 'Number',   'Standard'),
                array('AdministrativeFeePct', 70, $this->translate("Admin. fee"),       'Number',   'Standard'),
                array('PrincipalGraceMargin', 70, $this->translate("Kp grace"),         'Number'),
                array('DelayGrace',          100, $this->translate("Delay grace"),      'Number'),
                array('DelayPenaltyRate',    100, $this->translate("Delay rate"),       'Number',   'Standard')
            );
        return $this;
    }
       
    static function getLoanProductOptions($type = '', $id = 0)
    {
        if(!$id) return array();
        /*
        switch($type) {
            case 'Program': 
                return Zend_Registry::get('db')->fetchPairs("select LoanProductId, Name from loan_products 
                    where ProgramId = ? order by Name", $id);
        }
         * 
         */
        return array();
    }
       
    static function getLoanProductData($id = 0)
    {
        $table = new LoanProducts();
        if(!$id) return array_fill_keys($table->info(Zend_Db_Table_Abstract::COLS),'');
        return $table->find($id)->current()->toArray();
    }
}